
namespace tphp {

<?php
//命名空间必须是程序脚本的第一条语句
//declare(encoding='UTF-8');

    echo "------------- tc ------------------- \n";
    $aa=1;$bb=22;
    echo $aa+$bb.PHP_EOL;

    class Tclass {
        var $v1;
        var $v2;

        function __construct($v1,$v2) {
            echo "tc class construct:".$v1.", ".$v2.PHP_EOL;
            $this->v1 = $v1;
            $this->v2 = $v2;
        }
        function __destruct(){
            echo "tc class destruct".PHP_EOL;
        }

        //__call() 方法在调用不可访问的实例方法时执行
        //__callStatic()方法则在调用不可访问的静态方法时执行
        function __call($name, $args) {
            echo "tc call fun:".$name.', args:'.print_r($args).PHP_EOL;
            foreach ($args as $v) {
                echo $v.PHP_EOL;
            }
        }

        //final:无法被继承
        final function show(){echo "tc values:".$this->v1.", ".$this->v2.PHP_EOL;}

        function get_v1()  {return $this->v1;}
        function get_v2()  {return $this->v2;}
        function set_v1($v){$this->v1 = $v;}
        function set_v2($v){$this->v2 = $v;}
    }

    $tc = new Tclass(1,22);
    $tc1 = new Tclass(11,4322);
    //$tc->set_v1('tr4');
    //$tc->set_v2(341);
    echo "tc v1:".$tc->get_v1().PHP_EOL;
    echo "tc v2:".$tc->get_v2().PHP_EOL;
    echo "tc1 v1:".$tc1->get_v1().PHP_EOL;
    echo "tc1 v2:".$tc1->get_v2().PHP_EOL;
    echo "tc1 desc:".Tclass::class.PHP_EOL;
    $tc->t1(13,22,461);
    //;

    //-------------------------------------------------------------------------------------

    class Stclass extends Tclass {
        //function show(){echo "tc values:".$this->v1.", ".$this->v2.PHP_EOL;}

        function show_v1() {
            echo "stc--tc v1:".$this->v1.PHP_EOL;
        }
        static $st_v1 = 22331;
        const cs_v1 = 'tyre';
    }

    echo "------------- stc ------------------- \n";

    $stc = new Stclass(32,98);
    echo "stc v1:".$stc->v1.PHP_EOL;
    $stc->show_v1();
    $stc->set_v1(443);
    echo "stc v1:".$stc->get_v1().PHP_EOL;
    echo "stc st-v1:".Stclass::$st_v1.PHP_EOL;
    echo "stc cs-v1:".Stclass::cs_v1.PHP_EOL;

    echo "------------- interface ------------------- \n";

    interface iIntel {
        function set_v($v);     //必须实现
    }
    class tIntel implements iIntel {
        var $v1;

        function __construct($v) {
            $this->v1 = $v;
        }
        function set_v($v) {
            $this->v1 = $v;
        }
    }
    $it = new tIntel(43211);
    echo "it v1:".$it->v1.PHP_EOL;
    $it->set_v(66);
    echo "it v1(later):".$it->v1.PHP_EOL;

    echo '------------------ over -----------------------';


?>

}

<!-- http://47.96.22.83:8187/tphp/tclass.php -->

